import java.util.Arrays;
import java.util.List;
import java.util.Stack;

public class 逆波兰表达式求值 {
    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack();
        for(int i=0;i<tokens.length;i++){
            if (tokens[i].equals("+")){
                int secondNum = stack.pop();
                int firstNum = stack.pop();
                stack.push(firstNum + secondNum);
            }else if(tokens[i].equals("-")){
                int secondNum = stack.pop();
                int firstNum = stack.pop();
                stack.push(firstNum - secondNum);
            }else if(tokens[i].equals("*")){
                int secondNum = stack.pop();
                int firstNum = stack.pop();
                stack.push(firstNum * secondNum);
            }else if(tokens[i].equals("/")){
                int secondNum = stack.pop();
                int firstNum = stack.pop();
                stack.push(firstNum / secondNum);
            }else{
                stack.push(Integer.parseInt(tokens[i]));
            }
        }
        return stack.pop();
    }
    public static void main(String[] args) {
        String[] tokens = {"2", "0", "30", "56", "0", "+", "-", "+", "-"};
        System.out.println(evalRPN(tokens));
    }
}
